package com.atguigu.cmsService.controller;


import com.atguigu.cmsService.entity.CrmBanner;
import com.atguigu.cmsService.service.CrmBannerService;
import com.atguigu.commonUtils.Result;
import com.atguigu.commonUtils.ResultUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author Chen Wen bo
 * @since 2021-08-10
 */
@Api(tags = "轮播图管理")
@RestController
@RequestMapping("/cmsService/bannerAdmin")
@CrossOrigin
public class BannerAdminController {

    @Resource
    private CrmBannerService crmBannerService;

    @ApiOperation("分页查询轮播图")
    @GetMapping("/pageBanner/{current}/{size}")
    public Result<IPage<CrmBanner>> pageBanner(@PathVariable Long current, @PathVariable Long size) {
        IPage<CrmBanner> page = crmBannerService.pageBanner(current, size);
        return ResultUtil.success(page);
    }

    @ApiOperation("添加轮播图")
    @PostMapping("/addBanner")
    public Result<CrmBanner> addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.addBanner(crmBanner);
        return ResultUtil.success();
    }

    @ApiOperation("修改轮播图")
    @PutMapping("/updateBanner")
    public Result<CrmBanner> updateBanner(@RequestBody CrmBanner crmBanner) {
        crmBannerService.updateBanner(crmBanner);
        return ResultUtil.success();
    }

    @ApiOperation("删除轮播图")
    @DeleteMapping("/deleteBanner/{id}")
    public Result<CrmBanner> deleteBanner(@PathVariable String id){
        crmBannerService.deleteBanner(id);
        return ResultUtil.success();
    }

}

